package excelGUI;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JFileChooser;

import java.awt.BorderLayout;
import net.miginfocom.swing.MigLayout;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JToolBar;

import excelGUI.dataProc.DataStub;
import excelGUI.dataProc.DataStub.TextLabelListener;

import javax.swing.JMenuBar;
import javax.swing.JMenu;
import java.awt.Button;
import java.awt.Color;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.util.ArrayList;

import javax.swing.JTextPane;
import javax.swing.JScrollPane;
import java.awt.TextArea;
import javax.swing.JTextField;
import javax.swing.JComboBox;

public class Window {

	private JFrame frame;
	private int lineCount = 0;
	private DataStub stub;
	private JTextField textField;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Window window = new Window();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public Window() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setBounds(100, 100, 900, 900);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(null);

		TextArea textArea = new TextArea();
		textArea.setBounds(461, 482, 391, 300);
		textArea.setRows(8);
		textArea.setEditable(false);
		frame.getContentPane().add(textArea);

		textField = new JTextField();
		textField.setBounds(21, 52, 126, 35);
		frame.getContentPane().add(textField);
		textField.setColumns(10);

		JComboBox comboBox = new JComboBox();
		comboBox.setBounds(58, 135, 52, 35);
		frame.getContentPane().add(comboBox);

		JMenuBar menuBar = new JMenuBar();
		frame.setJMenuBar(menuBar);

		Button btnImport = new Button("IMPORT");
		btnImport.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				JFileChooser fc = new JFileChooser();

				fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
				int result = fc.showOpenDialog(btnImport);
				File file = fc.getSelectedFile();
				if (stub != null)
					stub.importFile(file);
			}
		});
		menuBar.add(btnImport);

		TextLabelListener listener1 = new TextLabelListener() {

			@Override
			public void setText(String text) {
				// TODO Auto-generated method stub
				textArea.append("\r\n" + lineCount++ + ": " + text);
			}

		};
		stub = new DataStub();
		stub.addListener(listener1);
		Button btnSearch = new Button("SEARCH");
		menuBar.add(btnSearch);

		Button btnUpdate = new Button("UPDATE");
		menuBar.add(btnUpdate);

		Button btnInsert = new Button("INSERT");
		menuBar.add(btnInsert);
	}
}
